/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package millenium3dchess;

/**
 *
 * @author Kenneth
 */
import java.util.ArrayList;
import java.awt.image.BufferedImage;
import millenium3dchess.Player.Error;

public abstract class Chessman {
    public Gamevector position;
    public ArrayList<GameSquare> moveList;
    public int cost; //used for the AI
    public Game.Color color;
    private boolean moved = false;
    private boolean captured = false;
    BufferedImage icon, smallIcon;
    
    abstract void updateMoveList();
    @Override
    abstract public String toString();
    
    public boolean move(GameSquare square){
        moved = true;
        updateMoveList();
        if(moveList.contains(square) && !square.occupied()){
            Game.getBoard()[position.getX()][position.getY()][position.getZ()].setChessman(null);
            position = square.getPosition();
            if(Game.getBoard()[position.getX()][position.getY()][position.getZ()].occupied()){
                Game.getBoard()[position.getX()][position.getY()][position.getZ()].getChessman().setCaptured(true);
            }
            Game.getBoard()[position.getX()][position.getY()][position.getZ()].setChessman(this);
            return true;
        }if(!moveList.contains(square)){
            Game.display.handlePlayerError(Error.INVALID_MOVE);
            Game.display.displayPotentialMoves(Game.getBoard()[position.getX()][position.getY()][position.getZ()]);
        }
        return false;
    }
    
    public boolean captured(){
        return captured;
    }
    
    public void setCaptured(boolean t){
        captured = t;
    }
    
    public boolean movedYet(){
        return moved;
    }
}
